package com.chapter15generics.section3.generics;

import java.util.Iterator;

/**
 * 类适配器模式
 * 使用继承的方式实现
 */
public class IterableFibonacci1 extends Fibonacci implements Iterable<Integer> {
    private int n;
    public IterableFibonacci1(int count){
        this.n = count;
    }
    @Override
    public Iterator<Integer> iterator() {
        return new Iterator<Integer>() {
            @Override
            public boolean hasNext() {
                return n > 0;
            }

            @Override
            public Integer next() {
                n--;
                return IterableFibonacci1.this.next();
            }
        };
    }

    public static void main(String[] args) {
        for(int i : new IterableFibonacci1(5)){
            System.out.print(i + " ");
        }
    }
}
